var CDR =CDR||{};

//模块主窗口
CDR.IVPNAndBSSPanel = Ext.extend(Ext.Panel,{
	 closable: true,
   	 autoScroll:true,
   	 width:'100%',
initComponent : function() {
   			this.tbar =  this.buildBbar() ;
   			var gd = new CDRIVPNGridPanel() ;
   				this.items = [new QueryStatCDRivpnForm({
					thisGrid:gd
				}),gd] ;
			this.formPanel =  new Ext.Window({
	   			layout:"fit",
	   			title: "按条件查询信息",
	   			closeAction: 'hide',
				resizable:false,
				modal:true,
				width:550,
				height:350,
				items :[new QueryCDRIVPNForm({
					thisGrid:gd
				})]
   			});
   				this.updatePanel =  null ;
   		CDR.IVPNAndBSSPanel.superclass.initComponent.call(this);
   	}
   	,updateIvpnData : function(btn) {
   		 var mPanel = btn.ownerCt.ownerCt;
   		 var gp = mPanel.items.get(1) ;
   		 var rows= gp.getSelectionModel().getSelections(); 
   		 if(rows.length==0) {
 			MsgTip.msg({
			 	msg:"请选择一条记录"
			 	,cmp: mPanel
			 	,pos:"top"
			 	,time:2
			});
   			 return ;
   		 }
   		 if(!mPanel.updatePanel) {
   			mPanel.updatePanel = new Ext.Window({
	   			layout:"fit",
	   			title: "处理问题",
	   			closeAction: 'hide',
				resizable:false,
				modal:true,
				width:400,
				height:200,
				items :[{
					xtype:'form'
					,layout:'form'
					,border:false
					,labelAlign:"left"
					,frame:true
					,items:[{
						fieldLabel:'处理描述'
						,xtype:'textarea'
						,labelWidth:65
						,name:'tsCdrUserResults.dealText'
						,height:100
						,anchor:'95%'
					}]
					,minButtonWidth:50
			   		,buttonAlign:'center'
				   	,buttons:[{
				   		text:'提交'
				   		,handler:function(btn) {
				   			var form = btn.ownerCt.ownerCt.getForm();
				   				mPanel.execInfo(mPanel,form);
				   			} 
				   		}]
				}]
				
   			});
   		}
   	    mPanel.updatePanel.show();
   	},	execInfo: function(m,form) {
   		var gp = m.items.get(1) ; 	
   		var rows= gp.getSelectionModel().getSelections(); 
   		var ids = "";
   		var types = "";
   			
   		for(var i=0 ;i<rows.length;i++) {
   			if(i==0) {
   				ids = rows[i].data['seqId'] ;
   			}else{
   				ids = ids +","+rows[i].data['seqId'] ;
   			}
   		}
   		form.submit( {	
				waitTitle : '请稍候...',
				waitMsg : '正在提交表单数据,请稍候...',
				method : 'post',
				params : {
					ids:ids, 
					types:this.types=3
				},
				
				url : 'cdr_updateCdrFlag.action',
				scope : this,
				success : function(form, action) {
					var Result=action.result;
					if(Result.success) {
						gp.getStore().reload();
						m.updatePanel.hide() ;
						MsgTip.msg({
						 	msg:"处理成功~~"
						 	,cmp: m
						 	,pos:"top"
						 	,time:2
						});
					} else {
						m.updatePanel.hide() ;
						MsgTip.msg({
						 	msg:"处理异常,请重试~"
						 	,cmp: m
						 	,pos:"top"
						 	,time:2
						});
					}
				},
				failure : function() {
						m.updatePanel.hide() ;
						MsgTip.msg({
						 	msg:"网络异常,请重试~"
						 	,cmp: m
						 	,pos:"top"
						 	,time:2
						});
					}
				});
   	}
   	
   	,queryHighFeeUser : function(btn) {
   		 var tform = btn.ownerCt.ownerCt.formPanel;
   	     tform.show();
   	},exportData:function(btn) {
   		var gp = btn.ownerCt.ownerCt.items.get(1) ;
   			var baseParams = gp.getStore().baseParams;
   		var ul = Ext.urlEncode(baseParams);
   		var st = gp.getStore();
   		Ext.MessageBox.confirm("确认", "确定导出?", function(btn) {
		if (btn == "yes") {
			window.location.href ="cdr_exportexportCdrTsCdrUserResultToExcel.action?limit="+st.totalLength;
		
		}
		});
   		
   	},
buildBbar: function() {
   		return [
   		{
   				text : "显示查询",
   				iconCls: 'ico-dot-search-open',
   				handler:function(btn){
   					var m = btn.ownerCt.ownerCt;
   					var g = m.items.get(1);
   					var a = m.items.get(0);
   					a.setHeight(70);
   					a.searchBtn = btn;
   					if(a.collapsed) {
   						var h1 = m.getHeight()-m.tbar.dom.clientHeight-a.getHeight();
   						a.expand(true);
   						g.setHeight(h1-70);
   						btn.setText("隐藏查询");
   						btn.setIconClass("ico-dot-search-hidden");
   					} else {
   						a.collapse(true);
   						g.setHeight(m.getHeight()-m.tbar.dom.clientHeight-1);
   						btn.setText("显示查询");
   						btn.setIconClass("ico-dot-search-open");
   					}
   				}
   			},'-',{
   				text : "问题处理",
   				handler :this.updateIvpnData,
   				iconCls: 'ico-dot-edit-news'
   			}
//   			{
//   				text : "按条件查询",
//   				handler :this.queryHighFeeUser,
//   				iconCls: 'ico-dot-search'
//   			}
   			,'-',{
   				text : "数据导出",
   				handler :this.exportData,
   				iconCls: 'ico-dot-report'
   			}
   				,'->',{
                    	text:'使用说明'					
                    	,iconCls:'ico-dot-book-question'
                    	,handler:function(){
                    		SM.Explanation.showExplanation(43);
                    	}
                    }
   			];
   	}
  	
});



//按条话单用户
QueryCDRIVPNForm = Ext.extend(Ext.form.FormPanel,{
	text:"表单",
	layout:"form",
	region : "center",
	labelAlign:"right",
	width:550,
	height:300,
	frame:true,
	initComponent: function(){
	var cityNameSelect = new Ext.data.JsonStore({
//	    url: "Settle_getCityCode.action",//第一个comboBox的json数据的URL地址
  		url: "highFee_getCityCode.action?type=1",//第一个comboBox的json数据的URL地址
	    root: "root",
	    fields: ["paramValue", "displayValue"]
	});
	this.items=[{fieldLabel : '归属地市',
							name : 'eparchyCode',
							xtype : 'combo',
							editable : false,
							mode : 'remote',
							triggerAction : 'all',
							valueField: "paramValue",
   							displayField: "displayValue",
							store : areaCodeSelect,
							emptyText:"请选择",
							anchor:"90%",
							listeners : {
		 						"select": function(combo){
									combo.ownerCt.getForm().findField("cityCode").reset();
									cityNameSelect.baseParams={'areaCode':combo.getValue()};
									cityNameSelect.load();
		 						}
							}
						},{fieldLabel : '归属区县',
							name : 'cityCode',
							xtype : 'combo',
							editable : false,
							mode : 'remote',
							triggerAction : 'all',
							valueField: "paramValue",
   							displayField: "displayValue",
							store : cityNameSelect,
							emptyText:"请选择",
							anchor:"90%"
						},{fieldLabel : '稽核日期',
							name : 'checkdate',
							xtype : 'datefield',
							editable : false,
							mode : 'local',
							
							triggerAction : 'all',
							store : getCyids(),//  [['0','请选择'],['201303','201303'],['201304','201304'],['201305','201305']],
							anchor:"90%",
							emptyText:"请选择"
					    },{fieldLabel : '网别',
							name : 'nettypecode',
							xtype : 'combo',
							editable : false,
							mode : 'local',
							emptyText:"请选择",
							triggerAction : 'all',
							store : [['10','2G'],['33','3G']],
							anchor:"90%"
						}
		];
	  QueryCDRIVPNForm.superclass.initComponent.call(this);
	},
	buttonAlign :'center',
	minButtonWidth:60,
	buttons:[{
		text:"确定",
		handler : function(btn){
		    var thisForm = btn.ownerCt.ownerCt.getForm();
		    var checkdate = thisForm.findField('checkdate').getValue();	 
//		    	checkDate = checkDate?checkDate.format("Ymd"):"";
//		    	 var statDay = thisForm.findField('checkDate').getValue();	 
//		    	statDay = statDay?statDay.format("Ymd"):"";	    	    
		    var nettypecode = thisForm.findField('nettypecode').getValue();
			var eparchycode = thisForm.findField('eparchyCode').getValue();
			var citycode = thisForm.findField('cityCode').getValue();
			
		    var store = btn.ownerCt.ownerCt.thisGrid.getStore();
		    btn.ownerCt.ownerCt.thisGrid.recordStart = 1;
		    store.baseParams = {
						'tsCdrUserResults.cityCode':citycode,
		    			'tsCdrUserResults.netTypeCode':nettypecode,
		    		    'tsCdrUserResults.checkDate':checkdate,
		    			'tsCdrUserResults.eparchyCode':eparchycode
			};

            store.load({params:{start:0, limit:200}});
		    
		   this.ownerCt.ownerCt.ownerCt.hide();//隐藏弹出页面
		}
	}, {
		text : '重置',
		handler : function() {this.ownerCt.ownerCt.form.reset();}
	}, {
		text : '取消',
		handler : function() {this.ownerCt.ownerCt.ownerCt.hide();}
	}]
});




CDRIVPNGridPanel = Ext.extend(Ext.grid.EditorGridPanel,{
	title : '话单VPN和BSS属性不一致列表',
	header: false,
	loadMask:{msg:'加载中...'},
	enableDragDrop: false,
	height: 560,
	columnLines:true,
	allowHeaderWrap:true,
	allowWrap:false,
//	viewConfig :{
//        //forceFit: true
//    },
	initComponent : function() {
       	var thisGrid = this;
       	this.recordStart = 1 ;
    	var settleCmSelectionModel = new Ext.grid.CheckboxSelectionModel({
                                dataIndex: "uid",
                sortable: false,
                singleSelect:false,
                width:20
		});
		var settleUserNew = new　Ext.grid.RowNumberer({
		　　header　:　"序号",
		　　width　:　35
		});
		this.columns　=　[settleCmSelectionModel,settleUserNew
//		    {
//				header:'稽核日期'
//				,sortable:true
//				,dataIndex:"checkDate"
//				,headerAlign :"center"
//				,align :"left"
//				,allowHeaderWrap:true
//				,allowWrap:false
//				,width:80
//				,renderer:function(V){
//				var mydate =new Date(V);
//				return mydate.format("Ymd");
//				}
//			 }
				,{header:'归属地市',
				sortable:true,
				dataIndex:"eparchyCode",
				width:70
				,headerAlign :"center"
				,align :"left"
				,allowHeaderWrap:true
				,allowWrap:false
			},{
				header:'归属区县',
				sortable:true,
				dataIndex:"cityCode",
				width:100
				,headerAlign :"center"
				,align :"left"
				,allowHeaderWrap:true
				,allowWrap:false
			},{
				header:'网别',
				sortable:true,
				dataIndex:"netTypeCode",
				//renderer:changerNetTypeCode,
				width:100
				,headerAlign :"center"
				,align :"left"
				,allowHeaderWrap:true
				,allowWrap:false
			},{
				header:'手机号码',
				sortable:true,
				dataIndex:"serialNumber",
				width:120
				,headerAlign :"center"
				,align :"left"
				,allowHeaderWrap:true
				,allowWrap:false
			},{
		        header:'业务类型',
				sortable:true,
				dataIndex:"bizType",
				//renderer:changerBizTypeNew,
				 width:120
				,headerAlign :"center"
				,align :"center"
				,allowHeaderWrap:true
				,allowWrap:false
			}
			,{
				header:'用户名称',
				sortable:true,
				dataIndex:"custName",
				width:100
				,headerAlign :"center"
				,align :"center"
				,cellTip:true
				,allowHeaderWrap:true
				,allowWrap:false
			}
			,{
				header:'用户编码',
				sortable:true,
				dataIndex:"userId",
				width:150
				,headerAlign :"center"
				,align :"center"
				,allowHeaderWrap:true
				,allowWrap:false
			}
			,{
						header:'是否处理',
						sortable:true,
						headerAlign:"center",
						dataIndex:"dealFlag",
						renderer:function(v) {
							return v==1?"已处理":"未处理";
						}
					},{
						header:'处理描述',
						sortable:true,
						headerAlign:"center",
						dataIndex:"dealText",
						cellTip:true,
						renderer:function(value, metaData, record, rowIndex, colIndex, store) {
			   			metaData.attr = ' ext:qtip="' + value + '"';
			   			return value ;
			   			}
					}
		] ;
	
//      ToFixed: function (v) {
//    	  return parseFloat(v).toFixed(2);
//      }

		var dataStore = new Ext.data.JsonStore({
			url : 'cdr_getTsCdrUserResult.action',			
			root: 'root',
	        totalProperty: 'totalProperty',
			idProperty: 'seqId',
	        fields: [
					'taskSeq','seqId','userId','serialNumber','bizType','eparchyCode','cityCode','areaName','custId',
					'custName','custType','netTypeCode','channelNo','ratePath','checkDate','flag','dbNo'
					,'dealTime','dealFlag','dealText','dealTime']
			});
	    dataStore.baseParams ={'tsCdrUserResults':null};
		this.store = dataStore;
		this.sm = settleCmSelectionModel;
		this.bbar = new Ext.PagingToolbar({
			pageSize : 200,
			store : dataStore,
			displayInfo : true,
			displayMsg : '第 {0} - {1} 条  共 {2} 条',
			emptyMsg : "没有记录",
			listeners:{
				beforechange:function(pt,obj) {
					thisGrid.recordStart = obj.start+1 ;
				    
				}
			}
		});
		dataStore.load({
			params:{
				start:0,
				limit:200
			}
		});
	CDRIVPNGridPanel.superclass.initComponent.call(this);
	}

});

//条件查询隐藏出现
QueryStatCDRivpnForm = Ext.extend(Ext.form.FormPanel,{
	text:"表单",
	layout:"form",
	region : "center",
	labelAlign:"right",
	collapsible:true,
	collapsed:false,
	header:false,
	width:"100%",
	height:1,
	frame:true,
	layout:'table',
	layoutConfig:{
	tableAttrs: {
		align:'left'
	 },
	columns: 5
 	},
	initComponent: function(){
	var cityNameSelect = new Ext.data.JsonStore({
	    url: "highFee_getCityCode.action?type=1",//第一个comboBox的json数据的URL地址
	    root: "root",
	    fields: ["paramValue", "displayValue"]
	});
	this.items=[{ 
		    	layout : "form",
		    	xtype:'panel',
		    	colspan:1,
		    	items:[{fieldLabel : '归属地市',
							name : 'eparchyCode',
							xtype : 'combo',
							editable : false,
							mode : 'remote',
							triggerAction : 'all',
							valueField: "paramValue",
   							displayField: "displayValue",
							store : areaCodeSelect,
							emptyText:"请选择",
							width:100,
							listeners : {
		 						"select": function(combo){
									combo.ownerCt.ownerCt.getForm().findField("cityCode").reset();
									cityNameSelect.baseParams={'areaCode':combo.getValue()};
									cityNameSelect.load();
		 						}
							}
						}]},{ 
		    	layout : "form",
		    	xtype:'panel',
		    	colspan:1,
		    	items:[{fieldLabel : '归属区县',
							name : 'cityCode',
							xtype : 'combo',
							editable : false,
							mode : 'remote',
							triggerAction : 'all',
							valueField: "paramValue",
   							displayField: "displayValue",
							store : cityNameSelect,
							emptyText:"请选择",
							width:100
						}]}
//                                		,{ 
//		    	layout : "form",
//		    	xtype:'panel',
//		    	colspan:1,
//		    	items:[{fieldLabel : '稽核日期',
//							name : 'checkdate',
//							xtype : 'datefield',
//							editable : false,
//							mode : 'local',
//							format:'Y-m-d',
//							triggerAction : 'all',
//							store : getCyids(),//  [['0','请选择'],['201303','201303'],['201304','201304'],['201305','201305']],
//							width:100,
//							emptyText:"请选择"
//					    }]}
					 ,{ 
		    	layout : "form",
		    	xtype:'panel',
		    	colspan:1,
		    	items:[{fieldLabel : '网别',
                                			name : 'netTypeCode',
                                			xtype : 'combo',
                                			editable : false,
                                			mode : 'local',
                                			emptyText:"请选择",
                                			triggerAction : 'all',
                                			store : [[null,'全部'],['10','2G用户'],['33','3G用户']],
                                			width:100,
                                		}]}	  
		];
	  QueryStatCDRivpnForm.superclass.initComponent.call(this);
	},
	buttonAlign :'center',
	minButtonWidth:60,
	buttons:[{
	text:"确定",
		handler : function(btn){
		    var thisForm = btn.ownerCt.ownerCt.getForm();
		  		    var thisForm = btn.ownerCt.ownerCt.getForm();
		  //  var checkdate = thisForm.findField('checkdate').getValue();	 	    
		    var netTypeCode = thisForm.findField('netTypeCode').getValue();
			var eparchycode = thisForm.findField('eparchyCode').getValue();
			var citycode = thisForm.findField('cityCode').getValue();	
		    var store = btn.ownerCt.ownerCt.thisGrid.getStore();
		    btn.ownerCt.ownerCt.thisGrid.recordStart = 1;
		    store.baseParams = {
		    			'tsCdrUserResults.cityCode':citycode,
		    			'tsCdrUserResults.netTypeCode':netTypeCode,
		    		  //  'tsCdrUserResults.checkDate':checkdate,
		    			'tsCdrUserResults.eparchyCode':eparchycode
			};

            store.load({params:{start:0, limit:200}});
		    
		   //this.ownerCt.ownerCt.ownerCt.hide();//隐藏弹出页面
		}
	}, {
		text : '重置',
		handler : function() {this.ownerCt.ownerCt.form.reset();}
	}, {
		text : '关闭',
		handler : function() {
		this.ownerCt.ownerCt.collapse(true);
			var m = this.ownerCt.ownerCt.ownerCt;
                                   	var g = m.items.get(1);
                                   	var a = m.items.get(0);
			g.setHeight(m.getHeight()-m.tbar.dom.clientHeight-1);
   			this.ownerCt.ownerCt.searchBtn.setText("显示查询");
   			this.ownerCt.ownerCt.searchBtn.setIconClass("ico-dot-search-open");
		}
	}]
});